import './common'

import { getQuery } from './tools'
import http from "axios";

http({
  method: 'GET',
  url: `https://api.yizhanketang.cn/api/v1/todos/${getQuery().objectid}`
}).then(({data}) => {
  const {content, description} = data.data
  $('#content').val(content)
  $('#desc').val(description)
}).catch(e => {
  alert(e)
}).finally(() => {
})

$('.btn-wrapper a').eq(0).on('click', function () {
  console.log($('#content').val(), $('#desc').val())
  http({
    method: 'POST',
    url: `https://api.yizhanketang.cn/api/v1/todos/${getQuery().objectid}`,
    data: {
      content: $('#content').val(),
      description: $('#desc').val()
    }
  }).then(() => {
    location.href = `show.html?objectid=${getQuery().objectid}`
  })
})

$('#del').on('click', function () {
  const ID = getQuery().objectid
  http({
    method: 'POST',
    url: `https://api.yizhanketang.cn/api/v1/todos/${ID}/delete`
  }).then(() => {
    location.href = 'index.html'
  })
})
